package com.zzh.sum1;
/*
* 在数组中找n个数和的暴力求法
* */
public class Sum1 {
    private static int size;
    private static int[] a;
    private static int sum;
    public static void main(String[] args) {
        a=new int[]{1,2,3,4,5};
        size=a.length;
        sum=10;
        boolean[] x = new boolean[size];
        enumNumber(x,0,0);
    }
    public static void enumNumber(boolean[] x,int i,int has){
        if (i>=size){
            return;
        }
        if (has+a[i]==sum){
            x[i]=true;
            myPrint(x);
        }
        //这里可以使用分支界定法，缩小范围
        //思路是将比较过的值
        x[i]=true;
        enumNumber(x,i+1,has+a[i]);
        x[i]=false;
        enumNumber(x,i+1,has);
    }
    public static void myPrint( boolean[] x){
        for (int i=0;i<x.length;i++){
            if (x[i]){
                System.out.printf("%d ",a[i]);
            }
        }
        System.out.println();
    }
}
